package com.tianqu.tms.www.cardect.controller;

import com.tianqu.tms.core.base.TmsController;
import com.tianqu.tms.core.base.TxController;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.exception.TransactionException;
import com.tianqu.tms.dto.TmsDetectInfoDto;
import com.tianqu.tms.entity.TmsDetectInfo;
import com.tianqu.tms.entity.TmsDetectNormal;

public class CarDetectPDFResultController extends TmsController {
	public static final String CARSERIAL = "carSerial";
	private static final String NORMAL = "normal";

	@Override
	public void execute(UserContext uc) throws Exception {

		TxController controller = TxController.getTxController();

		// 添加事务提交异常捕获
		try {
			controller.begin();
			// 获得车辆ID
			String carSerial = uc.getParameter(CARSERIAL);
			// 根据车辆ID查询检测报告信息
			TmsDetectInfo carInfo = TmsDetectInfo.getInstance();
			TmsDetectInfoDto dto = carInfo.getAllocateInfoById(carSerial);
			if (dto != null) {
				// 根据车辆ID查询检测信息
				TmsDetectNormal normal = TmsDetectNormal.getInstance();
				normal = normal.findDetectNormalInfoById(dto.getCarDetectId());
				normal.setChkTime(dto.getChkTime());
				uc.setAttribute(NORMAL, normal);

			}
			controller.commit();
		} catch (Exception e) {
			try {
				controller.rollback();
			} catch (TransactionException e1) {
				throw new TmsException(TmsException.DB_TXCRROR, e1);
			}
			// 系统异常
			if (e instanceof TmsException) {
				throw e;
			}
			throw new TmsException(TmsException.DB_TXCRROR, e);
		}

	}

}
